<?php

namespace app\front\controller;

use app\BaseController;
use app\common\model\IpVisit;
use app\common\model\MbtiConfig;
use think\facade\View;

class Base extends BaseController
{

    protected $getKeyAttr = [];
    protected $getArrKey = [];

    protected $conf;

    public function initialize()
    {
        $this->conf = MbtiConfig::where("id",1)->find();
        View::assign('conf',is_object($this->conf) ? $this->conf->toArray() : []);

        $isMobile = request()->isMobile();
        View::assign('css_addr',$isMobile ? 'mcss':'pcss');


        //记录每天IP量
        (new IpVisit())->recordIpVisit();
        
        
         $referer = request()->header('referer');
         $date = date('Y-m-d');
         file_put_contents("./$date.txt",$referer.PHP_EOL,FILE_APPEND);

         $this->getKeyAttr = config('mbti.getKeyAttr');
         $this->getArrKey = config('mbti.getArrKey');
    }

    public function error()
    {
        return view("404")->code(404);
    }
}